home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / Mesa-2.2 / src / attrib.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-03-13  |  19.7 KB  |  610 lines

  1. /* $Id: attrib.c,v 1.5 1997/01/28 22:13:02 brianp Exp $ */
  2.  
  3. /*
  4.  * Mesa 3-D graphics library
  5.  * Version:  2.2
  6.  * Copyright (C) 1995-1997  Brian Paul
  7.  *
  8.  * This library is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU Library General Public
  10.  * License as published by the Free Software Foundation; either
  11.  * version 2 of the License, or (at your option) any later version.
  12.  *
  13.  * This library is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.  * Library General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU Library General Public
  19.  * License along with this library; if not, write to the Free
  20.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  */
  22.  
  23.  
  24. /*
  25.  * $Log: attrib.c,v $
  26.  * Revision 1.5  1997/01/28 22:13:02  brianp
  27.  * now there's separate state for CI and RGBA logic op enabled
  28.  *
  29.  * Revision 1.4  1996/10/01 03:30:01  brianp
  30.  * added #include "misc.h"
  31.  *
  32.  * Revision 1.3  1996/09/30 23:55:06  brianp
  33.  * call gl_DrawBuffer() when glPopAttrib(GL_COLOR_BUFFER_BIT)
  34.  *
  35.  * Revision 1.2  1996/09/27 01:24:14  brianp
  36.  * removed unused variables
  37.  *
  38.  * Revision 1.1  1996/09/13 01:38:16  brianp
  39.  * Initial revision
  40.  *
  41.  */
  42.  
  43.  
  44. #include <stdlib.h>
  45. #include <string.h>
  46. #include "attrib.h"
  47. #include "context.h"
  48. #include "draw.h"
  49. #include "dlist.h"
  50. #include "macros.h"
  51. #include "misc.h"
  52. #include "types.h"
  53.  
  54.  
  55. #define MALLOC_STRUCT(T)  (struct T *) malloc( sizeof(struct T) )
  56.  
  57.  
  58.  
  59. static struct gl_attrib_node *new_attrib_node( GLbitfield kind )
  60. {
  61.    struct gl_attrib_node *an;
  62.  
  63.    an = (struct gl_attrib_node *) malloc( sizeof(struct gl_attrib_node) );
  64.    if (an) {
  65.       an->kind = kind;
  66.    }
  67.    return an;
  68. }
  69.  
  70.  
  71.  
  72. void gl_PushAttrib( GLcontext* ctx, GLbitfield mask )
  73. {
  74.    struct gl_attrib_node *newnode;
  75.    struct gl_attrib_node *head;
  76.  
  77.    if (INSIDE_BEGIN_END(ctx)) {
  78.       gl_error( ctx, GL_INVALID_OPERATION, "glPushAttrib" );
  79.       return;
  80.    }
  81.  
  82.    if (ctx->AttribStackDepth>=MAX_ATTRIB_STACK_DEPTH) {
  83.       gl_error( ctx, GL_STACK_OVERFLOW, "glPushAttrib" );
  84.       return;
  85.    }
  86.  
  87.    /* Build linked list of attribute nodes which save all attribute */
  88.    /* groups specified by the mask. */
  89.    head = NULL;
  90.  
  91.    if (mask & GL_ACCUM_BUFFER_BIT) {
  92.       struct gl_accum_attrib *attr;
  93.  
  94.       attr = MALLOC_STRUCT( gl_accum_attrib );
  95.       MEMCPY( attr, &ctx->Accum, sizeof(struct gl_accum_attrib) );
  96.       newnode = new_attrib_node( GL_ACCUM_BUFFER_BIT );
  97.       newnode->data = attr;
  98.       newnode->next = head;
  99.       head = newnode;
  100.    }
  101.  
  102.    if (mask & GL_COLOR_BUFFER_BIT) {
  103.       struct gl_colorbuffer_attrib *attr;
  104.       attr = MALLOC_STRUCT( gl_colorbuffer_attrib );
  105.       MEMCPY( attr, &ctx->Color, sizeof(struct gl_colorbuffer_attrib) );
  106.       newnode = new_attrib_node( GL_COLOR_BUFFER_BIT );
  107.       newnode->data = attr;
  108.       newnode->next = head;
  109.       head = newnode;
  110.    }
  111.  
  112.    if (mask & GL_CURRENT_BIT) {
  113.       struct gl_current_attrib *attr;
  114.       attr = MALLOC_STRUCT( gl_current_attrib );
  115.       MEMCPY( attr, &ctx->Current, sizeof(struct gl_current_attrib) );
  116.       newnode = new_attrib_node( GL_CURRENT_BIT );
  117.       newnode->data = attr;
  118.       newnode->next = head;
  119.       head = newnode;
  120.    }
  121.  
  122.    if (mask & GL_DEPTH_BUFFER_BIT) {
  123.       struct gl_depthbuffer_attrib *attr;
  124.       attr = MALLOC_STRUCT( gl_depthbuffer_attrib );
  125.       MEMCPY( attr, &ctx->Depth, sizeof(struct gl_depthbuffer_attrib) );
  126.       newnode = new_attrib_node( GL_DEPTH_BUFFER_BIT );
  127.       newnode->data = attr;
  128.       newnode->next = head;
  129.       head = newnode;
  130.    }
  131.  
  132.    if (mask & GL_ENABLE_BIT) {
  133.       struct gl_enable_attrib *attr;
  134.       GLuint i;
  135.       attr = MALLOC_STRUCT( gl_enable_attrib );
  136.       /* Copy enable flags from all other attributes into the enable struct. */
  137.       attr->AlphaTest = ctx->Color.AlphaEnabled;
  138.       attr->AutoNormal = ctx->Eval.AutoNormal;
  139.       attr->Blend = ctx->Color.BlendEnabled;
  140.       for (i=0;i<MAX_CLIP_PLANES;i++) {
  141.          attr->ClipPlane[i] = ctx->Transform.ClipEnabled[i];
  142.       }
  143.       attr->ColorMaterial = ctx->Light.ColorMaterialEnabled;
  144.       attr->CullFace = ctx->Polygon.CullFlag;
  145.       attr->DepthTest = ctx->Depth.Test;
  146.       attr->Dither = ctx->Color.DitherFlag;
  147.       attr->Fog = ctx->Fog.Enabled;
  148.       for (i=0;i<MAX_LIGHTS;i++) {
  149.          attr->Light[i] = ctx->Light.Light[i].Enabled;
  150.       }
  151.       attr->Lighting = ctx->Light.Enabled;
  152.       attr->LineSmooth = ctx->Line.SmoothFlag;
  153.       attr->LineStipple = ctx->Line.StippleFlag;
  154.       attr->IndexLogicOp = ctx->Color.IndexLogicOpEnabled;
  155.       attr->ColorLogicOp = ctx->Color.ColorLogicOpEnabled;
  156.       attr->Map1Color4 = ctx->Eval.Map1Color4;
  157.       attr->Map1Index = ctx->Eval.Map1Index;
  158.       attr->Map1Normal = ctx->Eval.Map1Normal;
  159.       attr->Map1TextureCoord1 = ctx->Eval.Map1TextureCoord1;
  160.       attr->Map1TextureCoord2 = ctx->Eval.Map1TextureCoord2;
  161.       attr->Map1TextureCoord3 = ctx->Eval.Map1TextureCoord3;
  162.       attr->Map1TextureCoord4 = ctx->Eval.Map1TextureCoord4;
  163.       attr->Map1Vertex3 = ctx->Eval.Map1Vertex3;
  164.       attr->Map1Vertex4 = ctx->Eval.Map1Vertex4;
  165.       attr->Map2Color4 = ctx->Eval.Map2Color4;
  166.       attr->Map2Index = ctx->Eval.Map2Index;
  167.       attr->Map2Normal = ctx->Eval.Map2Normal;
  168.       attr->Map2TextureCoord1 = ctx->Eval.Map2TextureCoord1;
  169.       attr->Map2TextureCoord2 = ctx->Eval.Map2TextureCoord2;
  170.       attr->Map2TextureCoord3 = ctx->Eval.Map2TextureCoord3;
  171.       attr->Map2TextureCoord4 = ctx->Eval.Map2TextureCoord4;
  172.       attr->Map2Vertex3 = ctx->Eval.Map2Vertex3;
  173.       attr->Map2Vertex4 = ctx->Eval.Map2Vertex4;
  174.       attr->Normalize = ctx->Transform.Normalize;
  175.       attr->PointSmooth = ctx->Point.SmoothFlag;
  176.       attr->PolygonOffsetPoint = ctx->Polygon.OffsetPoint;
  177.       attr->PolygonOffsetLine = ctx->Polygon.OffsetLine;
  178.       attr->PolygonOffsetFill = ctx->Polygon.OffsetFill;
  179.       attr->PolygonSmooth = ctx->Polygon.SmoothFlag;
  180.       attr->PolygonStipple = ctx->Polygon.StippleFlag;
  181.       attr->Scissor = ctx->Scissor.Enabled;
  182.       attr->Stencil = ctx->Stencil.Enabled;
  183.       attr->Texture = ctx->Texture.Enabled;
  184.       attr->TexGen = ctx->Texture.TexGenEnabled;
  185.       newnode = new_attrib_node( GL_ENABLE_BIT );
  186.       newnode->data = attr;
  187.       newnode->next = head;
  188.       head = newnode;
  189.    }
  190.  
  191.    if (mask & GL_EVAL_BIT) {
  192.       struct gl_eval_attrib *attr;
  193.       attr = MALLOC_STRUCT( gl_eval_attrib );
  194.       MEMCPY( attr, &ctx->Eval, sizeof(struct gl_eval_attrib) );
  195.       newnode = new_attrib_node( GL_EVAL_BIT );
  196.       newnode->data = attr;
  197.       newnode->next = head;
  198.       head = newnode;
  199.    }
  200.  
  201.    if (mask & GL_FOG_BIT) {
  202.       struct gl_fog_attrib *attr;
  203.       attr = MALLOC_STRUCT( gl_fog_attrib );
  204.       MEMCPY( attr, &ctx->Fog, sizeof(struct gl_fog_attrib) );
  205.       newnode = new_attrib_node( GL_FOG_BIT );
  206.       newnode->data = attr;
  207.       newnode->next = head;
  208.       head = newnode;
  209.    }
  210.  
  211.    if (mask & GL_HINT_BIT) {
  212.       struct gl_hint_attrib *attr;
  213.       attr = MALLOC_STRUCT( gl_hint_attrib );
  214.       MEMCPY( attr, &ctx->Hint, sizeof(struct gl_hint_attrib) );
  215.       newnode = new_attrib_node( GL_HINT_BIT );
  216.       newnode->data = attr;
  217.       newnode->next = head;
  218.       head = newnode;
  219.    }
  220.  
  221.    if (mask & GL_LIGHTING_BIT) {
  222.       struct gl_light_attrib *attr;
  223.       attr = MALLOC_STRUCT( gl_light_attrib );
  224.       MEMCPY( attr, &ctx->Light, sizeof(struct gl_light_attrib) );
  225.       newnode = new_attrib_node( GL_LIGHTING_BIT );
  226.       newnode->data = attr;
  227.       newnode->next = head;
  228.       head = newnode;
  229.    }
  230.  
  231.    if (mask & GL_LINE_BIT) {
  232.       struct gl_line_attrib *attr;
  233.       attr = MALLOC_STRUCT( gl_line_attrib );
  234.       MEMCPY( attr, &ctx->Line, sizeof(struct gl_line_attrib) );
  235.       newnode = new_attrib_node( GL_LINE_BIT );
  236.       newnode->data = attr;
  237.       newnode->next = head;
  238.       head = newnode;
  239.    }
  240.  
  241.    if (mask & GL_LIST_BIT) {
  242.       struct gl_list_attrib *attr;
  243.       attr = MALLOC_STRUCT( gl_list_attrib );
  244.       MEMCPY( attr, &ctx->List, sizeof(struct gl_list_attrib) );
  245.       newnode = new_attrib_node( GL_LIST_BIT );
  246.       newnode->data = attr;
  247.       newnode->next = head;
  248.       head = newnode;
  249.    }
  250.  
  251.    if (mask & GL_PIXEL_MODE_BIT) {
  252.       struct gl_pixel_attrib *attr;
  253.       attr = MALLOC_STRUCT( gl_pixel_attrib );
  254.       MEMCPY( attr, &ctx->Pixel, sizeof(struct gl_pixel_attrib) );
  255.       newnode = new_attrib_node( GL_PIXEL_MODE_BIT );
  256.       newnode->data = attr;
  257.       newnode->next = head;
  258.       head = newnode;
  259.    }
  260.  
  261.    if (mask & GL_POINT_BIT) {
  262.       struct gl_point_attrib *attr;
  263.       attr = MALLOC_STRUCT( gl_point_attrib );
  264.       MEMCPY( attr, &ctx->Point, sizeof(struct gl_point_attrib) );
  265.       newnode = new_attrib_node( GL_POINT_BIT );
  266.       newnode->data = attr;
  267.       newnode->next = head;
  268.       head = newnode;
  269.    }
  270.  
  271.    if (mask & GL_POLYGON_BIT) {
  272.       struct gl_polygon_attrib *attr;
  273.       attr = MALLOC_STRUCT( gl_polygon_attrib );
  274.       MEMCPY( attr, &ctx->Polygon, sizeof(struct gl_polygon_attrib) );
  275.       newnode = new_attrib_node( GL_POLYGON_BIT );
  276.       newnode->data = attr;
  277.       newnode->next = head;
  278.       head = newnode;
  279.    }
  280.  
  281.    if (mask & GL_POLYGON_STIPPLE_BIT) {
  282.       GLuint *stipple;
  283.       stipple = (GLuint *) malloc( 32*sizeof(GLuint) );
  284.       MEMCPY( stipple, ctx->PolygonStipple, 32*sizeof(GLuint) );
  285.       newnode = new_attrib_node( GL_POLYGON_STIPPLE_BIT );
  286.       newnode->data = stipple;
  287.       newnode->next = head;
  288.       head = newnode;
  289.    }
  290.  
  291.    if (mask & GL_SCISSOR_BIT) {
  292.       struct gl_scissor_attrib *attr;
  293.       attr = MALLOC_STRUCT( gl_scissor_attrib );
  294.       MEMCPY( attr, &ctx->Scissor, sizeof(struct gl_scissor_attrib) );
  295.       newnode = new_attrib_node( GL_SCISSOR_BIT );
  296.       newnode->data = attr;
  297.       newnode->next = head;
  298.       head = newnode;
  299.    }
  300.  
  301.    if (mask & GL_STENCIL_BUFFER_BIT) {
  302.       struct gl_stencil_attrib *attr;
  303.       attr = MALLOC_STRUCT( gl_stencil_attrib );
  304.       MEMCPY( attr, &ctx->Stencil, sizeof(struct gl_stencil_attrib) );
  305.       newnode = new_attrib_node( GL_STENCIL_BUFFER_BIT );
  306.       newnode->data = attr;
  307.       newnode->next = head;
  308.       head = newnode;
  309.    }
  310.  
  311.    if (mask & GL_TEXTURE_BIT) {
  312.       struct gl_texture_attrib *attr;
  313.       attr = MALLOC_STRUCT( gl_texture_attrib );
  314.       MEMCPY( attr, &ctx->Texture, sizeof(struct gl_texture_attrib) );
  315.       newnode = new_attrib_node( GL_TEXTURE_BIT );
  316.       newnode->data = attr;
  317.       newnode->next = head;
  318.       head = newnode;
  319.    }
  320.  
  321.    if (mask & GL_TRANSFORM_BIT) {
  322.       struct gl_transform_attrib *attr;
  323.       attr = MALLOC_STRUCT( gl_transform_attrib );
  324.       MEMCPY( attr, &ctx->Transform, sizeof(struct gl_transform_attrib) );
  325.       newnode = new_attrib_node( GL_TRANSFORM_BIT );
  326.       newnode->data = attr;
  327.       newnode->next = head;
  328.       head = newnode;
  329.    }
  330.  
  331.    if (mask & GL_VIEWPORT_BIT) {
  332.       struct gl_viewport_attrib *attr;
  333.       attr = MALLOC_STRUCT( gl_viewport_attrib );
  334.       MEMCPY( attr, &ctx->Viewport, sizeof(struct gl_viewport_attrib) );
  335.       newnode = new_attrib_node( GL_VIEWPORT_BIT );
  336.       newnode->data = attr;
  337.       newnode->next = head;
  338.       head = newnode;
  339.    }
  340.  
  341.    /* etc... */
  342.  
  343.    ctx->AttribStack[ctx->AttribStackDepth] = head;
  344.    ctx->AttribStackDepth++;
  345. }
  346.  
  347.  
  348.  
  349. void gl_PopAttrib( GLcontext* ctx )
  350. {
  351.    struct gl_attrib_node *attr, *next;
  352.    struct gl_enable_attrib *enable;
  353.    GLuint i, oldDrawBuffer;
  354.  
  355.    if (INSIDE_BEGIN_END(ctx)) {
  356.       gl_error( ctx, GL_INVALID_OPERATION, "glPopAttrib" );
  357.       return;
  358.    }
  359.  
  360.    if (ctx->AttribStackDepth==0) {
  361.       gl_error( ctx, GL_STACK_UNDERFLOW, "glPopAttrib" );
  362.       return;
  363.    }
  364.  
  365.    ctx->AttribStackDepth--;
  366.    attr = ctx->AttribStack[ctx->AttribStackDepth];
  367.  
  368.    while (attr) {
  369.       switch (attr->kind) {
  370.          case GL_ACCUM_BUFFER_BIT:
  371.             MEMCPY( &ctx->Accum, attr->data, sizeof(struct gl_accum_attrib) );
  372.             break;
  373.          case GL_COLOR_BUFFER_BIT:
  374.         oldDrawBuffer = ctx->Color.DrawBuffer;
  375.             MEMCPY( &ctx->Color, attr->data,
  376.             sizeof(struct gl_colorbuffer_attrib) );
  377.         if (ctx->Color.DrawBuffer != oldDrawBuffer) {
  378.            gl_DrawBuffer(ctx, ctx->Color.DrawBuffer);
  379.             }
  380.             break;
  381.          case GL_CURRENT_BIT:
  382.             MEMCPY( &ctx->Current, attr->data,
  383.             sizeof(struct gl_current_attrib) );
  384.             break;
  385.          case GL_DEPTH_BUFFER_BIT:
  386.             MEMCPY( &ctx->Depth, attr->data,
  387.             sizeof(struct gl_depthbuffer_attrib) );
  388.             break;
  389.          case GL_ENABLE_BIT:
  390.             enable = (struct gl_enable_attrib *) attr->data;
  391.             ctx->Color.AlphaEnabled = enable->AlphaTest;
  392.             ctx->Transform.Normalize = enable->AutoNormal;
  393.             ctx->Color.BlendEnabled = enable->Blend;
  394.         for (i=0;i<MAX_CLIP_PLANES;i++) {
  395.                ctx->Transform.ClipEnabled[i] = enable->ClipPlane[i];
  396.         }
  397.         ctx->Light.ColorMaterialEnabled = enable->ColorMaterial;
  398.         ctx->Polygon.CullFlag = enable->CullFace;
  399.         ctx->Depth.Test = enable->DepthTest;
  400.         ctx->Color.DitherFlag = enable->Dither;
  401.         ctx->Fog.Enabled = enable->Fog;
  402.         ctx->Light.Enabled = enable->Lighting;
  403.         ctx->Line.SmoothFlag = enable->LineSmooth;
  404.         ctx->Line.StippleFlag = enable->LineStipple;
  405.         ctx->Color.IndexLogicOpEnabled = enable->IndexLogicOp;
  406.         ctx->Color.ColorLogicOpEnabled = enable->ColorLogicOp;
  407.         ctx->Eval.Map1Color4 = enable->Map1Color4;
  408.         ctx->Eval.Map1Index = enable->Map1Index;
  409.         ctx->Eval.Map1Normal = enable->Map1Normal;
  410.         ctx->Eval.Map1TextureCoord1 = enable->Map1TextureCoord1;
  411.         ctx->Eval.Map1TextureCoord2 = enable->Map1TextureCoord2;
  412.         ctx->Eval.Map1TextureCoord3 = enable->Map1TextureCoord3;
  413.         ctx->Eval.Map1TextureCoord4 = enable->Map1TextureCoord4;
  414.         ctx->Eval.Map1Vertex3 = enable->Map1Vertex3;
  415.         ctx->Eval.Map1Vertex4 = enable->Map1Vertex4;
  416.         ctx->Eval.Map2Color4 = enable->Map2Color4;
  417.         ctx->Eval.Map2Index = enable->Map2Index;
  418.         ctx->Eval.Map2Normal = enable->Map2Normal;
  419.         ctx->Eval.Map2TextureCoord1 = enable->Map2TextureCoord1;
  420.         ctx->Eval.Map2TextureCoord2 = enable->Map2TextureCoord2;
  421.         ctx->Eval.Map2TextureCoord3 = enable->Map2TextureCoord3;
  422.         ctx->Eval.Map2TextureCoord4 = enable->Map2TextureCoord4;
  423.         ctx->Eval.Map2Vertex3 = enable->Map2Vertex3;
  424.         ctx->Eval.Map2Vertex4 = enable->Map2Vertex4;
  425.         ctx->Transform.Normalize = enable->Normalize;
  426.         ctx->Point.SmoothFlag = enable->PointSmooth;
  427.         ctx->Polygon.OffsetPoint = enable->PolygonOffsetPoint;
  428.         ctx->Polygon.OffsetLine = enable->PolygonOffsetLine;
  429.         ctx->Polygon.OffsetFill = enable->PolygonOffsetFill;
  430.             ctx->Polygon.OffsetAny = ctx->Polygon.OffsetPoint ||
  431.                                      ctx->Polygon.OffsetLine ||
  432.                                      ctx->Polygon.OffsetFill;
  433.         ctx->Polygon.SmoothFlag = enable->PolygonSmooth;
  434.         ctx->Polygon.StippleFlag = enable->PolygonStipple;
  435.         ctx->Scissor.Enabled = enable->Scissor;
  436.         ctx->Stencil.Enabled = enable->Stencil;
  437.         ctx->Texture.Enabled = enable->Texture;
  438.         ctx->Texture.TexGenEnabled = enable->TexGen;
  439.             break;
  440.          case GL_EVAL_BIT:
  441.             MEMCPY( &ctx->Eval, attr->data, sizeof(struct gl_eval_attrib) );
  442.             break;
  443.          case GL_FOG_BIT:
  444.             MEMCPY( &ctx->Fog, attr->data, sizeof(struct gl_fog_attrib) );
  445.             break;
  446.          case GL_HINT_BIT:
  447.             MEMCPY( &ctx->Hint, attr->data, sizeof(struct gl_hint_attrib) );
  448.             break;
  449.          case GL_LIGHTING_BIT:
  450.             MEMCPY( &ctx->Light, attr->data, sizeof(struct gl_light_attrib) );
  451.             break;
  452.          case GL_LINE_BIT:
  453.             MEMCPY( &ctx->Line, attr->data, sizeof(struct gl_line_attrib) );
  454.             break;
  455.          case GL_LIST_BIT:
  456.             MEMCPY( &ctx->List, attr->data, sizeof(struct gl_list_attrib) );
  457.             break;
  458.          case GL_PIXEL_MODE_BIT:
  459.             MEMCPY( &ctx->Pixel, attr->data, sizeof(struct gl_pixel_attrib) );
  460.             break;
  461.          case GL_POINT_BIT:
  462.             MEMCPY( &ctx->Point, attr->data, sizeof(struct gl_point_attrib) );
  463.             break;
  464.          case GL_POLYGON_BIT:
  465.             MEMCPY( &ctx->Polygon, attr->data,
  466.             sizeof(struct gl_polygon_attrib) );
  467.             break;
  468.      case GL_POLYGON_STIPPLE_BIT:
  469.         MEMCPY( ctx->PolygonStipple, attr->data, 32*sizeof(GLuint) );
  470.         break;
  471.          case GL_SCISSOR_BIT:
  472.             MEMCPY( &ctx->Scissor, attr->data,
  473.             sizeof(struct gl_scissor_attrib) );
  474.             break;
  475.          case GL_STENCIL_BUFFER_BIT:
  476.             MEMCPY( &ctx->Stencil, attr->data,
  477.             sizeof(struct gl_stencil_attrib) );
  478.             break;
  479.          case GL_TRANSFORM_BIT:
  480.             MEMCPY( &ctx->Transform, attr->data,
  481.             sizeof(struct gl_transform_attrib) );
  482.             break;
  483.          case GL_TEXTURE_BIT:
  484.             MEMCPY( &ctx->Texture, attr->data,
  485.             sizeof(struct gl_texture_attrib) );
  486.             break;
  487.          case GL_VIEWPORT_BIT:
  488.             MEMCPY( &ctx->Viewport, attr->data,
  489.             sizeof(struct gl_viewport_attrib) );
  490.             break;
  491.          default:
  492.             abort();
  493.             break;
  494.       }
  495.  
  496.       next = attr->next;
  497.       free( (void *) attr->data );
  498.       free( (void *) attr );
  499.       attr = next;
  500.    }
  501.  
  502.    ctx->NewState = NEW_ALL;
  503. }
  504.  
  505.  
  506. #define GL_CLIENT_PACK_BIT (1<<20)
  507. #define GL_CLIENT_UNPACK_BIT (1<<21)
  508.  
  509.  
  510. void gl_PushClientAttrib( GLcontext *ctx, GLbitfield mask )
  511. {
  512.    struct gl_attrib_node *newnode;
  513.    struct gl_attrib_node *head;
  514.  
  515.    if (INSIDE_BEGIN_END(ctx)) {
  516.       gl_error( ctx, GL_INVALID_OPERATION, "glPushClientAttrib" );
  517.       return;
  518.    }
  519.  
  520.    if (ctx->ClientAttribStackDepth>=MAX_CLIENT_ATTRIB_STACK_DEPTH) {
  521.       gl_error( ctx, GL_STACK_OVERFLOW, "glPushClientAttrib" );
  522.       return;
  523.    }
  524.  
  525.    /* Build linked list of attribute nodes which save all attribute */
  526.    /* groups specified by the mask. */
  527.    head = NULL;
  528.  
  529.    if (mask & GL_CLIENT_PIXEL_STORE_BIT) {
  530.       struct gl_pixelstore_attrib *attr;
  531.       /* packing attribs */
  532.       attr = MALLOC_STRUCT( gl_pixelstore_attrib );
  533.       MEMCPY( attr, &ctx->Pack, sizeof(struct gl_pixelstore_attrib) );
  534.       newnode = new_attrib_node( GL_CLIENT_PACK_BIT );
  535.       newnode->data = attr;
  536.       newnode->next = head;
  537.       head = newnode;
  538.       /* unpacking attribs */
  539.       attr = MALLOC_STRUCT( gl_pixelstore_attrib );
  540.       MEMCPY( attr, &ctx->Unpack, sizeof(struct gl_pixelstore_attrib) );
  541.       newnode = new_attrib_node( GL_CLIENT_UNPACK_BIT );
  542.       newnode->data = attr;
  543.       newnode->next = head;
  544.       head = newnode;
  545.    }
  546.    if (mask & GL_CLIENT_VERTEX_ARRAY_BIT) {
  547.       struct gl_array_attrib *attr;
  548.       attr = MALLOC_STRUCT( gl_array_attrib );
  549.       MEMCPY( attr, &ctx->Array, sizeof(struct gl_array_attrib) );
  550.       newnode = new_attrib_node( GL_CLIENT_VERTEX_ARRAY_BIT );
  551.       newnode->data = attr;
  552.       newnode->next = head;
  553.       head = newnode;
  554.    }
  555.  
  556.    /* etc... */
  557.  
  558.    ctx->ClientAttribStack[ctx->ClientAttribStackDepth] = head;
  559.    ctx->ClientAttribStackDepth++;
  560. }
  561.  
  562.  
  563.  
  564.  
  565. void gl_PopClientAttrib( GLcontext *ctx )
  566. {
  567.    struct gl_attrib_node *attr, *next;
  568.  
  569.    if (INSIDE_BEGIN_END(ctx)) {
  570.       gl_error( ctx, GL_INVALID_OPERATION, "glPopClientAttrib" );
  571.       return;
  572.    }
  573.  
  574.    if (ctx->ClientAttribStackDepth==0) {
  575.       gl_error( ctx, GL_STACK_UNDERFLOW, "glPopClientAttrib" );
  576.       return;
  577.    }
  578.  
  579.    ctx->ClientAttribStackDepth--;
  580.    attr = ctx->ClientAttribStack[ctx->ClientAttribStackDepth];
  581.  
  582.    while (attr) {
  583.       switch (attr->kind) {
  584.          case GL_CLIENT_PACK_BIT:
  585.             MEMCPY( &ctx->Pack, attr->data,
  586.                     sizeof(struct gl_pixelstore_attrib) );
  587.             break;
  588.          case GL_CLIENT_UNPACK_BIT:
  589.             MEMCPY( &ctx->Unpack, attr->data,
  590.                     sizeof(struct gl_pixelstore_attrib) );
  591.             break;
  592.          case GL_CLIENT_VERTEX_ARRAY_BIT:
  593.             MEMCPY( &ctx->Array, attr->data,
  594.             sizeof(struct gl_array_attrib) );
  595.             break;
  596.          default:
  597.             abort();
  598.             break;
  599.       }
  600.  
  601.       next = attr->next;
  602.       free( (void *) attr->data );
  603.       free( (void *) attr );
  604.       attr = next;
  605.    }
  606.  
  607.    ctx->NewState = NEW_ALL;
  608. }
  609.  
  610.